//
//  UIFactory.swift
//  AocPrepare
//
//  Created by xieyi on 2021/3/31.
//

import Foundation
import  UIKit
 
public class UIFactory {
     
    /**
    * 创建文本标签控件
    */
    class func createLabel(title: String, textColor: UIColor, aligment: NSTextAlignment = .center, bgColor: UIColor = .clear, font: UIFont = UIFont.systemFont(ofSize: 16.0)) -> UILabel {
        let label = UILabel()
        label.textColor = textColor
        label.textAlignment = aligment
        label.backgroundColor = bgColor
        label.text = title
        label.font = font
        return label
    }
    
    class func createImageView() -> UIImageView {
        let imageview = UIImageView()
        return imageview
    }
    
    class func createView(color: UIColor = .clear) -> UIView {
        let view = UIView()
        view.backgroundColor = color
        return view
    }
    
    class func createTextView(text: String = "", bgcolor: UIColor = .clear, textcolor: UIColor = .black, font: UIFont = UIFont.systemFont(ofSize: 15.0)) -> UITextView {
        let textview = UITextView()
        textview.textColor = textcolor
        textview.backgroundColor = .clear
        textview.text = text
        textview.font = font
        return textview
        
    }
    
    class func stackViewWithAxis(axis: NSLayoutConstraint.Axis, alignment: UIStackView.Alignment, distribution: UIStackView.Distribution, spacing: CGFloat = 0) -> UIStackView {
        let stackView = UIStackView()
        stackView.axis = axis
        stackView.alignment = alignment
        stackView.distribution = distribution
        stackView.spacing = spacing
        return stackView
    }
    
    class func createButton(title: String = "", image: String = "", selectImage: String = "", titleColor: UIColor = .black) -> UIButton {
        let bt = UIButton.init(type: .custom)
        bt.setTitle(title, for: .normal)
        bt.setTitleColor(titleColor, for: .normal)
        if image != "" {
            bt.setImage(UIImage.init(named: image), for: .normal)
        }
        if selectImage != "" {
            bt.setImage(UIImage.init(named: selectImage), for: .selected)
        }
        return bt
        
    }
    
    class func createTable(bgcolor: UIColor = .white, separatorType: UITableViewCell.SeparatorStyle = .none) -> UITableView {
        let tableview = UITableView.init()
        tableview.separatorStyle = separatorType
        tableview.backgroundColor = .white
        return tableview
    }
}
